<?php
/**
 * @copyright meila.com
 * @author shaopu@
 * @name 
 * @param 
 *         $xxx = 作用
 * @static 
 *         XXX = 作用
 */

$dir = dirname(dirname(__FILE__));
include($dir.'/__queue_global.php');
include(SERVER_ROOT_PATH.'/include/config/ml_vdapei_config.php');

//ml_run_queue_check(ML_CRONPHP_VDAPEI_GEN); 

echo date('Y-m-d H:i:s');

//现在只能先提供假数据了
$uid='80';  
$oContent=new ml_model_dbContent();
$oContent->get_count_by_uid($uid);
$count=$oContent->get_data();

$total = $count[0]['num'] > ML_VDAPEI_TOTAL ? ML_VDAPEI_TOTAL:$count[0]['num'] ;
$block_num = ceil($total / ML_VDAPEI_PAGESIZE);

$oRedis=new ml_model_rdsCount();


for($i=0;$i<$block_num;$i++){

    $begin=$i * ML_VDAPEI_PAGESIZE;
    $rs=$oContent->get_content_by_uid($uid,$begin,ML_VDAPEI_PAGESIZE);

    $data=$oContent->get_data();
    foreach($data as $val){
        if(!in_array($val['uid'],$uids)){
            $uids[]=$val['uid'];
        }
        if(!in_array($val['rid'],$rids)){
            $rids[]=$val['rid'];
        }
    }

    $oRedis->getAttitudeCount($rids);
    $countAtti=$oRedis->get_data();
    $oRedis->getCommentCount($rids);
    $countComment=$oRedis->get_data();
    
    $nickArr=ml_tool_nick::uids2nicks($uids);

    foreach($data as &$val){
        
        $val['nick']=$nickArr[$val['uid']];
        $val['headPic']=ml_tool_picid::uid2portrait($val['uid']);
        $val['picurl200']=ml_tool_picid::pid2url($val['pic_id'],ML_USER_PICSIZE_PINBOARD,ML_PICTYPE_CONTENT);
        $size=getimagesize($val['picurl200']);
        $val['picWid']=$size[0];
        $val['picHit']=$size[1];
        $val['picurl']=ml_tool_picid::pid2url($val['pic_id'],ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);//先给320，后期给原图  @todo
        
        $val['cntAtti']=$countAtti[$val['rid']];
        $val['cntCom']=$countComment[$val['rid']];    
    }

    $aData = array(
        'block_num' => $block_num,
        'rows' => $data
    );
    $path = ML_VDAPEI_GEN_TMP_DIR.'/vdapei_block'.$i.'.json';
    $fp = fopen($path , 'w');
    fwrite($fp , json_encode($aData));
    
    fclose($fp);
}



?>